﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace XForms.Controls
{
    public class StandardForm : BaseComponents.BaseForm
    {
        /// <summary>
        /// Gets or Sets if this Form can be moved by clicking and dragging only on the Title bar or the entire Form.
        /// </summary>
        public Boolean TitlebarRestricted { get; set; }

        public StandardForm(Game game, String name)
            : base(game, name)
        {
        }

        protected override void UpdateMousePosition(GameTime gameTime)
        {
            MouseState mouse = Mouse.GetState();

            if (!this.IsMoving)
            {
                Boolean mouseX, mouseY;

                if ((mouse.X >= this.Location.X) && (mouse.X <= this.Location.X + this.Size.Width))
                    mouseX = true;
                else
                    mouseX = false;

                //Only force Mouse Over Code execution to the title bar, if we have one.
                if (this.HasTitleBar && this.TitlebarRestricted)
                {
                    if ((mouse.Y >= this.Location.Y) && (mouse.Y <= this.Location.Y + this.TitleBarSize))
                        mouseY = true;
                    else
                        mouseY = false;
                }
                else
                {
                    if ((mouse.Y >= this.Location.Y) && (mouse.Y <= this.Location.Y + this.Size.Height))
                        mouseY = true;
                    else
                        mouseY = false;
                }

                if (mouseX && mouseY)
                    this.IsMouseOver = true;
                else
                    this.IsMouseOver = false;
            }
        }
    }
}
